//
//  DictateButtonView.swift
//  DentalFormula
//
//  Created by AMalashin on 23.09.2023.
//

import SwiftUI

struct DictateButtonView: View {
    private let activeFgColor = Color.yellow
    private let activeBgColor = Color.red
    private let inactiveFgColor = Color.red
    private let inactiveBgColor = Color.green
    
    @Binding var active: Bool
    @State var start = {}
    @State var stop = {}

    var body: some View {
        Button(action: active ? deactivate : activate) {
            Circle()
                .fill(active ? activeBgColor : inactiveBgColor)
                .strokeBorder(lineWidth: 6)
                .overlay {
                    VStack {
                        Image(systemName: "mic")
                            .imageScale(.large)
                            .foregroundColor(active ? activeFgColor : inactiveFgColor)
                        Text(active ? "dictate.button.recording" : "dictate.button.record")
                            .foregroundColor(active ? activeFgColor : inactiveFgColor)
                    }
                }
        }
        .contentShape(Circle())
        .foregroundColor(active ? activeFgColor : inactiveFgColor)
        .frame(width: 200)
        .padding()
    }
    
    private func activate() {
        start()
        active.toggle()
        print("activate")
    }
    
    private func deactivate() {
        stop()
        active.toggle()
        print("deactivate")
    }
}

#Preview {
    DictateButtonView(active: .constant(false))
}
